package demo;

/**
 * Created with IntelliJ IDEA
 * Description:
 * User:恋恋
 * Date:2022-10-02
 * Time:10:19
 */
class Solution {
    public int removeElement(int[] nums, int val) {
        int count = 0;
        int left=0, right=nums.length-1;
        while (left<=right){
            if(nums[left]!=val){
                count++;
                left++;
                continue;
            }
            if(nums[left]==val && nums[right]==val){
                right--;
                continue;
            }
            if(nums[left]==val && nums[right]!=val){
                int temp=nums[left];
                nums[left]=nums[right];
                nums[right]=temp;
                count++;
                left++;
                right--;
                continue;
            }
        }
        return count;
    }
}
    public class TestDemo {
        public static void main(String[] args) {
            int[] arr = new int[]{2};
            Solution solution = new Solution();
            int len = solution.removeElement(arr, 3);
            System.out.println(len);
            for (int i = 0; i < len; i++) {
                System.out.print(arr[i]);

            }
        }

    }
